package com.chixing.day08_interface;
/*
    把 A implements Comparable<T> 比较两个对象的先后顺序
    实现了自然顺序

    TreeMap，TreeSet
*/
public class Product implements Comparable<Product>{
    private String proName;
    private int proSale;
    private float proPrice;

    public Product(String proName, int proSale, int proPrice) {
        this.proName = proName;
        this.proSale = proSale;
        this.proPrice = proPrice;
    }

    //两个商品比较先后顺序（先比较销量，再比较价格,再比较商品名称）
    @Override
    public int compareTo(Product anotherProduct) {
        if (this.proSale!=anotherProduct.proSale)
            return this.proSale-anotherProduct.proSale;
        else if (this.proPrice!=anotherProduct.proPrice)
            return (int) (this.proPrice-anotherProduct.proPrice);
        else
            return this.proName.compareTo(anotherProduct.proName);

        /*if (this.proSale==anotherProduct.proSale){
            if (this.proPrice==anotherProduct.proPrice)
                return 0;
            else
                return (int) (this.proPrice-anotherProduct.proPrice);
        } else
            return this.proSale-anotherProduct.proSale;*/
    }


}
